package com.easylinkin.linkappapi.positioning.controller;

import com.easylinkin.linkappapi.positioning.entity.QueryRealTimePosition;
import com.easylinkin.linkappapi.positioning.service.RealTimePositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @program: linkapp-group
 * @description: 实时追踪
 * @author: chenkaixuan
 * @create: 2021-06-24 10:29
 */
@Slf4j
@RestController
@RequestMapping("/realTimePosition")
public class RealTimePositionController {
    @Autowired
    RealTimePositionService realTimePositionService;

    /***
     *
     * @param queryRealTimePosition
     * @return
     */
    @PostMapping("get")
    public RestMessage getDeviceRealTimeData(@RequestBody QueryRealTimePosition queryRealTimePosition) {
        Assert.notNull(queryRealTimePosition, "参数不能为空");
//        Assert.notNull(queryRealTimePosition.getFunctionIdentifier(), "功能识别码不能为空");
        Assert.notNull(queryRealTimePosition.getDeviceCode(),"deviceCode 不能为空!");
        try {
            return RestBuilders.successBuilder().data(realTimePositionService.getDeviceRealTimeData(queryRealTimePosition)).build();
        } catch (Exception e) {
            log.error("实时跟踪查询错误msg:{}",e.getMessage());
            return RestBuilders.failureMessage().setCode("500").setMessage(e.getMessage());
        }
    }
}
